const express = require('express')
const axios = require('axios')
const path = require('path');
const app = express()
const port = 3000
const APPID = 'e39397cc'
const APISecret = 'MDc2MDZiOTgwZDExM2YwZWZhOTgwMzcz'
const APIKey = '0e5e11f2551b32e85d68e15ed39a446a'
const httpUrl = "https://spark-api.cn-huabei-1.xf-yun.com/v2.1/tti"
const CryptoJS = require('./static/crypto-js/crypto-js.js')
const parser = require('./static/fast-xml-parser/src/parser')
const base64 = require('base-64')
app.use(function (req, res, next) {
  // req:表示请求对象
  // res:表示响应对象
  // next:表示下一步
  // *：通配符
  res.setHeader('Access-Control-Allow-Origin', '*')//允许哪些域名请求我
  res.setHeader('Access-Control-Request-Methods', 'GET,POST,PUT,DELETE,OPTIONS')//允许哪些请求方式可以请求我
  res.setHeader('Access-Control-Allow-Headers', 'x-requested-with,content-type')//允许携带哪些请求头信息

  // **************上面的代码一写那么就等于这个服务器开启了跨域资源共享
  next()
})
app.get('/getimage', async (req, res) => {

  const url = 'http://123.60.219.214:8083/gpt4'
  const queryParams = req.query;
  console.log(queryParams);
  // 参数
  let params = {
    // messages: [
    //   {
    //     role: 'user',
    //     content: '你好'
    //   }
    // ],
    // temperature: 0.8,
    // top_p: 0.8,
    // penalty_score: 1,
    // disable_search: false,
    // enable_citation: false,
    response_format: "text"
  }
  axios({
    method: 'post',
    url: url,
    data: {
      messages: [
      {
        role: 'user',
        content: '主角的名字是“我是谁”的电视剧'
      }
    ],
    },
    headers: {
      'Content-Type': 'application/json;charset=UTF-8',
    },
  })
    .then((response) => {
      console.log(response,'8888888888888');
      res.send(response.data)
    })
    
})

app.listen(port, () => {
  console.log(`Example app listening on port ${port}`)
})